package com.imoblife.brainwavestus;

import com.imoblife.brainwavestus.customview.MenuList;
import com.imoblife.brainwavestus.model.Constant;
import com.imoblife.brainwavestus.obpurchaseSystem.OBpurchaseSystem;
import com.imoblife.brainwavestus.obpurchaseSystem.TusPointManager;
import com.imoblife.brainwavestus.share.ShareUtil;
import com.imoblife.brainwavestus.util.DialogUtil;
import com.imoblife.brainwavestus.util.NetUtil;

import android.app.Activity;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.ViewFlipper;
import android.widget.CompoundButton.OnCheckedChangeListener;


public class InfoActivity extends BaseActivity {
	
	private ScrollView mShowItemLayout;
	private ViewFlipper mViewFlipper;
	
	private Activity mActivity;
	@Override
	protected void onCreate(Bundle arg0) {		
		super.onCreate(arg0);
		
		mActivity = this;
		
		if(LaunchScreenActivity.IS_PAD){
			
			setContentView(R.layout.pad_info_layout);
		}else {
					 
			Drawable back = this.getResources().getDrawable(R.drawable.home_back);
			View view = LayoutInflater.from(this)
					.inflate(R.layout.phone_info_layout,null);
			view.setBackgroundDrawable(back);
			setContentView(view);
		}
		
		mShowItemLayout = (ScrollView)findViewById(R.id.show_item_layout);
		mViewFlipper =(ViewFlipper)findViewById(R.id.view_flipper);
		
		initTitleName(getString(R.string.info));
		
		if(LaunchScreenActivity.IS_PAD){
			
			initPadView();
		}
		
	}

	private void initPadView() {
		
		final CheckBox padAboutBrianwave 
				= (CheckBox)findViewById(R.id.about_brianwave);
		final CheckBox padAboutImoblife 
				= (CheckBox)findViewById(R.id.about_imoblife);
		
		padAboutBrianwave.setOnCheckedChangeListener(
				new OnCheckedChangeListener() {

			public void onCheckedChanged(CompoundButton buttonView,
					boolean isChecked) {

				if (isChecked) {

					onAboutBrainwaveClicked(null);
					ImageView imageView = (ImageView) mActivity
							.findViewById(R.id.about_bw_data);
					imageView.setImageResource(R.drawable.tb_bw);
					padAboutImoblife.setEnabled(true);
					padAboutImoblife.setChecked(false);
					padAboutBrianwave.setEnabled(false);
				}
			}
		});
		padAboutBrianwave.setChecked(true);
		
		padAboutImoblife.setOnCheckedChangeListener(
				new OnCheckedChangeListener() {

			public void onCheckedChanged(CompoundButton buttonView,
					boolean isChecked) {

				if (isChecked) {
					onAboutImoblifeClicked(null);
					padAboutBrianwave.setEnabled(true);
					padAboutBrianwave.setChecked(false);
					padAboutImoblife.setEnabled(false);
				}
			}
		});

	}

	@Override
	protected void onDestroy() {
		
		super.onDestroy();	
	}
	
	
	@Override
	public void finish() {
		
		if (mViewFlipper.getCurrentView() == mShowItemLayout) {
			mViewFlipper.showPrevious();
			return;
		}
		
		super.finish();
	}

	public void onAboutBrainwaveClicked(View v) {
		
		mShowItemLayout.removeAllViews();
		this.getLayoutInflater().inflate(R.layout.about_brainwaves,
				mShowItemLayout);			
		mViewFlipper.showNext();
	}
	
	public void onAboutImoblifeClicked(View v) {
		
		mShowItemLayout.removeAllViews();
		this.getLayoutInflater().inflate(R.layout.about_company,
				mShowItemLayout);
		mViewFlipper.showNext();
	}
	
	public void onTestImonialsClicked(View v) {
		
		mActivity.startActivity(new Intent(mActivity, TestimonialsActivity.class));
	}
	
	public void onSendFeedbackClicked(View v) {
		
		Intent email = new Intent(android.content.Intent.ACTION_SEND);

		email.putExtra(Intent.EXTRA_EMAIL,
				new String[] { "apple@downloadandroid.info" });

		email.putExtra(Intent.EXTRA_SUBJECT, mActivity.getResources()
				.getString(R.string.connect_email_title));

		email.setType("message/rfc822");

		this.startActivity(Intent.createChooser(email, mActivity
				.getResources().getText(R.string.app_name)));
	}
	
	public void onShareWithFriendsClicked(View v) {
		
		new ShareUtil(mActivity).showShareDialog(mActivity.getResources()
				.getString(R.string.dialog_title), mActivity
				.getString(R.string.share_url), mActivity
				.getString(R.string.share_title), mActivity
				.getString(R.string.share_content));
	}
	
	public void onAboutBrainwavesTusClicked(View v) {
		this.startActivity(new Intent(
				Intent.ACTION_VIEW,
				Uri.parse(Constant.URI_ABOUT_BRAINWAVES_TUS)));
	}
	
	public void onCompanyIconClicked(View v) {
		
		this.startActivity(new Intent(Intent.ACTION_VIEW, 
				Uri.parse(Constant.URI_ABOUT_IMOBLIFE)));
	}
	
	public void onMoreAppClicked(View v) {
		
		this.startActivity(new Intent(Intent.ACTION_VIEW, Uri
				.parse(Constant.URI_ABOUT_MORE_APP)));
	}
}
